package com.lighthouse.doc.comment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lighthouse.doc.comment.domain.KnowledgeDocCommentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.lighthouse.doc.comment.domain.KnowledgeDocComment;
import com.lighthouse.doc.comment.service.IKnowledgeDocCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档-用户评论关联Controller
 * 
 * @author ysz
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/doc/comment")
public class KnowledgeDocCommentController extends BaseController
{
    @Autowired
    private IKnowledgeDocCommentService knowledgeDocCommentService;

    /**
     * 查询文档-用户评论关联列表
     */
    @PreAuthorize("@ss.hasPermi('knowledge:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeDocCommentVO knowledgeDocCommentVO)
    {
        startPage();
        List<KnowledgeDocCommentVO> list = knowledgeDocCommentService.selectKnowledgeDocCommentListByDocId(knowledgeDocCommentVO);
        return getDataTable(list);
    }

//    /**
//     * 导出文档-用户评论关联列表
//     */
//    @PreAuthorize("@ss.hasPermi('knowledge:comment:export')")
//    @Log(title = "文档-用户评论关联", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, KnowledgeDocComment knowledgeDocComment)
//    {
//        List<KnowledgeDocComment> list = knowledgeDocCommentService.selectKnowledgeDocCommentList(knowledgeDocComment);
//        ExcelUtil<KnowledgeDocComment> util = new ExcelUtil<KnowledgeDocComment>(KnowledgeDocComment.class);
//        util.exportExcel(response, list, "文档-用户评论关联数据");
//    }

    /**
     * 获取文档-用户评论关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('knowledge:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") String commentId)
    {
        return success(knowledgeDocCommentService.selectKnowledgeDocCommentByCommentId(commentId));
    }

    /**
     * 新增文档-用户评论关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:comment:add')")
    @Log(title = "文档-用户评论关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowledgeDocComment knowledgeDocComment)
    {
        return toAjax(knowledgeDocCommentService.insertKnowledgeDocComment(knowledgeDocComment));
    }

    /**
     * 修改文档-用户评论关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:comment:edit')")
    @Log(title = "文档-用户评论关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowledgeDocComment knowledgeDocComment)
    {
        return toAjax(knowledgeDocCommentService.updateKnowledgeDocComment(knowledgeDocComment));
    }

    /**
     * 删除文档-用户评论关联
     */
    @PreAuthorize("@ss.hasPermi('knowledge:comment:remove')")
    @Log(title = "文档-用户评论关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable String[] commentIds)
    {
        return toAjax(knowledgeDocCommentService.deleteKnowledgeDocCommentByCommentIds(commentIds));
    }
}
